import {ConfigProvider, App as AppProvider, theme} from "antd";
import {useGlobalStore} from "@/store/global";
import {RefreshProvider} from "@/context/Refresh";
import {AliveScope} from 'react-activation';
import Router from "@/router";
import zhCN from 'antd/locale/zh_CN';
// import AutoFit from 'autofit.js'
import {useEffect} from "react";

const App = () => {

    const {isDark, primary, componentSize, compactAlgorithm, borderRadius} = useGlobalStore()
    const algorithm = () => {
        const algorithmArr = isDark ? [theme.darkAlgorithm] : [theme.defaultAlgorithm];
        if (compactAlgorithm) algorithmArr.push(theme.compactAlgorithm);
        return algorithmArr;
    };
    useEffect(() => {
        // AutoFit.init()
    }, []);
    return (
        <ConfigProvider
            locale={zhCN}
            componentSize={componentSize}
            theme={{token: {colorPrimary: primary, borderRadius}, algorithm: algorithm()}}
        >
                <AppProvider>
                    <RefreshProvider>
                        <AliveScope>
                            <Router/>
                        </AliveScope>
                    </RefreshProvider>
                </AppProvider>
        </ConfigProvider>
    );
}

export default App;
